package com.oscar.ehome.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.oscar.ehome.utils.util.ToastUtil;

/**
 * author: MengWanhe
 * date: On 2017/6/7
 * 监听网络
 */

public class ConnectionReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {

        if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)){
            ConnectivityManager mConnectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();
            if(netInfo != null && netInfo.isAvailable()) {
                // ToastUtil.show(context,"网络已连接");
            }else{
                ToastUtil.show(context,"网络不可以用,请检查网络是否连接");
            }
        }
    }
}
